package org.red_cross_service.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.red_cross_service.domain.entity.LearnRecordEntity;

import java.util.List;
import java.util.Map;

@Mapper
public interface LearnRecordMapper extends BaseMapper<LearnRecordEntity> {

    @Select("""
            SELECT l.*, a.* FROM rc_learn_record l
            JOIN rc_activity a ON l.activity_id = a.activity_id
            WHERE l.user_id = #{userId} ${sql}
            """)
    List<Map<String, String>> queryLearnRecord(@Param("sql") String sql, @Param("userId") Integer userId);


    @Update({
            "<script>",
            "<foreach collection='list' item='item' separator=';'>",
            "UPDATE rc_learn_record SET videos_process = #{item.videosProcess}, videos_status = #{item.videosStatus} WHERE record_id = #{item.recordId}",
            "</foreach>",
            "</script>"
    })
    int updateBatch(@Param("list") List<LearnRecordEntity> recordEntityList);
}
